package com.logic.saas.service;

import java.util.Map;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import com.logic.saas.enums.SessionKey;
import com.logic.saas.pojo.User;
import com.opensymphony.xwork2.ActionContext;
 
public abstract class BaseService {

	protected String infoMessage;
	protected String errorMesssage;
	protected ActionContext actionContext;
	protected Map<String, Object> session;
	protected HttpServletRequest request;
	protected boolean recordExists;
	
	
	
	public User getSessionUser(){
		User user = null;
		Map<String, Object> session = ActionContext.getContext().getSession();
		if(session != null){
			try {
				user = (User) session.get(SessionKey.USER);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
		return user;
	}
	
	
	public boolean isRecordExists() {
		return recordExists;
	}

	public void setRecordExists(boolean recordExists) {
		this.recordExists = recordExists;
	}

	public String getInfoMessage() {
		return infoMessage;
	}

	public void setInfoMessage(String infoMessage) {
		this.infoMessage = infoMessage;
	}

	public String getErrorMesssage() {
		return errorMesssage;
	}

	public void setErrorMesssage(String errorMesssage) {
		this.errorMesssage = errorMesssage;
	}

	public ActionContext getActionContext() {
		return ActionContext.getContext();
	}

	public Map<String, Object> getSession() {
		return ActionContext.getContext().getSession();
	}

	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}
	
}
